<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
    <meta name="format-detection" content="telephone=no, email=no, adress=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-touch-fullscreen" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="description" content="">
    <meta name="keywords" content="">
    <link type="text/css" rel="stylesheet" href="../css/reset.css" />
    <title></title>
    <style>
        #wrapper {
            width: 100%;
            height: 500px;
            overflow: hidden;
            position: relative;
        }

        #scroller {
            width: 100%;
            height: 840px;
            background-color: #FFF;
            position: absolute;
            z-index: 1;
        }

        ul li {
            width: 100%;
            height: 42px;
            line-height: 42px;
            border-bottom: 1px solid #CCC;
            text-align: center;
            box-sizing: border-box;
        }

        #wrapper p {
            position: absolute;
            text-align: center;
            height: 3rem;
            line-height: 3rem;
            color: red;
            width: 100%;
        }

        #wrapper p.p-1 {
            top: 0;
        }

        #wrapper p.p-2 {
            bottom: 0;
        }

        .footer p {
            line-height: 3rem;
            text-align: center;
        }
    </style>
</head>

<body>
    <div id="wrapper">
        <div id="scroller">
            <ul>
                <li>1</li>
                <li>2</li>
                <li>3</li>
                <li>4</li>
                <li>5</li>
                <li>6</li>
                <li>7</li>
                <li>8</li>
                <li>9</li>
                <li>10</li>
                <li>11</li>
                <li>12</li>
                <li>13</li>
                <li>14</li>
                <li>15</li>
                <li>16</li>
                <li>17</li>
                <li>18</li>
                <li>19</li>
                <li>20</li>
            </ul>
        </div>
        <p class="p-1">下拉刷新</p>
        <p class="p-2">上拉加载</p>
    </div>
    <div class="footer">
        <p>上面的容器是可以滚动的区域</p>
    </div>
    <script src="../js/jquery-1.8.3.min.js"></script>
    <script src="../js/iScroll.js"></script>
    <script>
        //实现上拉加载、下拉刷新  
        var myScroll = new IScroll('#wrapper', {
            scrollY: true,
            scrollX: false
        })

        myScroll.on('scrollEnd', function () {
            //因为值为负数，所以使用小于等于  
            if (this.y <= this.maxScrollY) {
                console.log('滑动到最底部了');
                var li = '<li>新的内容</li><li>新的内容</li><li>新的内容</li><li>新的内容</li><li>新的内容</li>';
                $('#scroller ul').append(li);
                $('#scroller').css({
                    height: $('#scroller').height() + (42 * 5) + 'px'
                });
                this.refresh();
            }
        })
    </script>
</body>
</html>